package com.night.attendance.web;

import cn.hutool.core.date.DateUtil;
import com.night.attendance.service.VacationService;
import com.night.common.entity.ResultVo;
import com.night.common.entity.attendance.VacationDO;
import com.night.common.entity.attendance.VacationQueryDO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Dark-Morning
 * 2022/10/20 10:05
 */
@RestController
@RequestMapping("api/attendance/vacation")
public class VacationController {
    @Autowired
    VacationService vacationService;

    @PostMapping("applyVacation")
    public ResultVo<?> applyVacation(@RequestBody VacationDO vacationDO) {
        vacationService.save(vacationDO);
        return ResultVo.SUCCESS;
    }

    @PostMapping("updateVacation")
    public ResultVo<?> updateVacation(@RequestBody VacationDO vacationDO) {
        vacationDO.setState(null);
        vacationDO.setCounsellor(null);
        vacationDO.setTeacherId(null);
        vacationDO.setInstruct(null);
        vacationDO.setApplyTime(DateUtil.now());
        vacationService.update(vacationDO);
        return ResultVo.SUCCESS;
    }

    @PostMapping("instructVacation")
    public ResultVo<?> instructVacation(@RequestBody VacationDO vacationDO) {
        vacationDO.setInstructTime(DateUtil.now());
        vacationService.update(vacationDO);
        return ResultVo.SUCCESS;
    }

    @PostMapping("list")
    public ResultVo<?> list(@RequestBody VacationQueryDO vacationQueryDO) {
        vacationService.listVacation(vacationQueryDO);
        return new ResultVo<>(vacationQueryDO.getPageBean());
    }

}
